﻿#!/usr/bin/env python
#coding:utf-8
from probe.core.level import *
from commands import *
from urllib2 import *
def webpage_visit(args):
    '''
    @Note:商城web测试(商城服务器专用)
    '''
    result = {}
    for page in args.get('list'):
        pagetext = ''
        ipaddr = getlanip()
        url = 'http://%s:%s'%(ipaddr, page)
        try:
            pagetext = urlopen(url).read()
        except:
            result['页面访问']=[url,'失败']
        if pagetext:
            if '200' not in pagetext:
                result['页面访问']=[url,'失败']
    if result:
        return WarningData(result)
    return InfoData(result)

def getlanip():
    '''
    @Note:获取本地内网IP地址
    '''
    ipaddr='''/sbin/ifconfig|awk -F : '/eth/ {getline;print $2}'|awk '/10/{print $1}' '''
    result = getoutput(ipaddr)
    return result
   
if __name__ == '__main__':
    print webpage_visit({'list':['8080/bl.html','8081/smgs/bl.html']})
